# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=usb-canary
pkgver=31.bb23552
pkgrel=3
pkgdesc='A Linux or OSX tool that uses psutil to monitor devices while your computer is locked. In the case it detects someone plugging in or unplugging devices it can be configured to send you an SMS or alert you via Slack or Pushover.'
arch=('any')
groups=('blackarch' 'blackarch-defensive')
url='https://github.com/errbufferoverfl/usb-canary'
license=('GPL3')
depends=('python2' 'python2-virtualenv')
makedepends=('git' 'python2-pip')
source=("git+https://github.com/errbufferoverfl/$pkgname.git")
sha512sums=('SKIP')
install="$pkgname.install"

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  sed -i '1i\six' requirements.txt
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md
  install -Dm 644 LICENSE.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm *.md LICENSE.txt

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
source venv/bin/activate
exec python2 usbcanary.py "\$@"
EOF

  chmod a+x "$pkgdir/usr/bin/$pkgname"
}

